﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Threading.Thread;
using static System.Console;

namespace Project_2
{
    /// <summary>
    /// 2.3 Mutex类 同步两个单独的程序 ,可用于两个不同进程，锁
    /// </summary>
    public class Unit_2_03
    {
        public static void Go()
        {
            const string MutexName = "C# 666";

            using (var m=new Mutex(false,MutexName))
            {
                if (!m.WaitOne(TimeSpan.FromSeconds(5), false))
                {
                    WriteLine("第二个实例已经启动");
                }
                else
                {
                    WriteLine("Running");
                    ReadLine();
                    m.ReleaseMutex();
                }   
            }
        }

    }

}
